<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>pkg_earn_info分页</title>
<div class="lay-box">
    <form class="layui-form" action="" style="margin-top: 10px">
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>
        <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
            <input type="text"  id="pkgName" required  placeholder="请输入包名"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <div style="width: 180px;display: inline-block;margin: 0 0 8px 20px;">
            <input type="text"  id="appName" required  placeholder="请输入应用名"
                   autocomplete="off"
                   class="layui-input">
        </div>
<#--        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">-->
<#--            <select name="status" id="status" lay-verify="" style="width: 300px">-->
<#--                <option value="">选择任务状态</option>-->
<#--                <option value="1"></option>-->
<#--                <option value="0">待提交</option>-->
<#--                <option value="-1">用户主动放弃</option>-->
<#--                <option value="-3">系统释放</option>-->
<#--            </select>-->
<#--        </div>-->

    </form>
    <button class="layui-btn" onclick="gradeEdit()">
        <i class="layui-icon">&#xe608;</i> 添加
    </button>
    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
    <span onclick="blackrecord(1)" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">禁用每日必赚下载</span>
    <span onclick="blackrecord(2)" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">禁用每日必赚签到</span>
    <span onclick="allrecord()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">禁用全部</span>
    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal " lay-event="baidu">百度一下</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal " lay-event="qimai">七麦一下</a>
    <a class="layui-btn layui-btn-xs" lay-event="save">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="record">完成记录</a>

</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.openDownload== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="openClick">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="openClick" {{
           d.openClick== 1 ? 'checked' : '' }}>
</script>
<script type="text/javascript">
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "pkg_earn_info";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/sys/pkgearninfo/list'
            ,
            autoSort: false,
        method: 'POST'
            ,
            where: {

            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}
                , { title: '操作', toolbar: '#barDemo', width: 600, align: 'center'}
                , {
                    field: 'pkgName',
                    title: '包名',
                    width: 300,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'finish',
                    title: '完成量',
                    width: 200,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'appName',
                    title: '应用名称',
                    width: 250,
                    align: 'center',
                    sort: true
                }
                // , {
                //     field: 'icon',
                //     title: ' icon图标',
                //     width: 150,
                //     align: 'center',
                //     sort: true
                // }
                , {
                    field: 'open_download',
                    title: '每日必赚',
                    width: 100,
                    align: 'center',
                    sort: true,
                    templet: '#switchTpl',
                    unresize: true
                }
                , {
                    field: 'open_click',
                    title: '签到',
                    width: 100,
                    align: 'center',
                    sort: true,
                    templet: '#openClick',
                    unresize: true
                }


                , {
                    field: 'create_time', title: '创建时间', templet: function (data) {
                        return dateFormat(data.createTime);
                    }, align: 'center', width: 200, sort: true
                }
                , {
                    field: 'modify_time', title: '修改时间', templet: function (data) {
                        return dateFormat(data.modifyTime);
                    }, align: 'center', width: 200, sort: true
                }


            ]]
            ,
            page: true
        });
        tableIns.on('sort(tableFilter)', function(obj){ //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            console.log(obj.field); //当前排序的字段名
            console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
            console.log(this); //当前排序的 th 对象

            //尽管我们的 table 自带排序功能，但并没有请求服务端。
            //有些时候，你可能需要根据当前排序的字段，重新向服务端发送请求，从而实现服务端排序，如：
            tableIns.reload('dataTableId', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });

          //  layer.msg('服务端排序。order by '+ obj.field + ' ' + obj.type);
        });
        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        form.on('switch(openClick)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenableClick(this.value, 1);
            } else {
                commonenableClick(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/pkgearninfo/delete",
                    type: 'post',
                    data: { "id": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'save') {
                layer_show("修改", "/sys/pkgearninfo/add?id=" + data.id, "650", "650");
            }else if (obj.event === 'baidu') {
                window.open("https://www.baidu.com/s?wd="+data.appName)
            }else if (obj.event === 'record') {
                window_show("每日必赚记录", "/sys/downloadmemberrecord/list?pkgName=" + data.pkgName, "650", "650");
            }else if (obj.event === 'qimai') {
                window.open("https://www.qimai.cn/search/android/market/6/search/"+data.pkgName);
            }
        });
    });

    function search() {
       var startDate = $("#star").val();
        var  endDate = $("#end").val();
        var appName = $("#appName").val();
        var pkgName = $("#pkgName").val();
        tableIns.reload('dataTableId', {
            where: {
                star: startDate, end: endDate,appName:appName,pkgName:pkgName
            }
            , page: {}
        });
    }



    function gradeEdit() {
        layer_show("新增", "/sys/pkgearninfo/add", "650", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/sys/pkgearninfo/enable",
            type: 'post',
            data: { "id": id, "openDownload": status},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }
    function commonenableClick(id, status) {
        $.ajax({
            url: "/sys/pkgearninfo/enable/click",
            type: 'post',
            data: { "id": id, "openClick": status},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }
    function blackrecord(type) {
        var list="";
        var checkStatus = tableIns.checkStatus('dataTableId');
        var dataList = checkStatus.data;
        if (dataList != null && dataList.length > 0) {

            for (var i = 0; i < dataList.length; i++) {
                list += dataList[i].id + ",";
            }
        }
        $.ajax({
            url: "/sys/pkgearninfo/enable/click/list",
            type: 'post',
            data: { "str": list,type:type},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }
    function allrecord() {
        blackrecord(1);
        blackrecord(2);
    }
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
